<?php
global $_GPC, $_W;
$GLOBALS['frames'] = $this->getMainMenu();

$where= " where uniacid=:uniacid";
$data[':uniacid']=$_W['uniacid'];
if($_GPC['keywords']){
	$where.=" and name LIKE  concat('%', :name,'%')";
	 $data[':name']=$_GPC['keywords'];  
}
	$pageindex = max(1, intval($_GPC['page']));

	$pagesize=10;
	$sql="select *  from " . tablename("zhtc_user") .$where." order by id desc";
	$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
	$list = pdo_fetchall($select_sql,$data);	
	$total=pdo_fetchcolumn("select count(*) from " . tablename("zhtc_user") .$where,$data);
	$pager = pagination($total, $pageindex, $pagesize);
	for($i=0;$i<count($list);$i++){
		$userid=$list[$i]['id'];
        $yxtime=time()-60*60*24*7;
        $yxnum=count(pdo_fetchall("select * from ".tablename("zhtc_userformid")." where user_id={$userid} and UNIX_TIMESTAMP(time)>={$yxtime}"));
        $list[$i]['yxnum']=$yxnum;
	}
	if($_GPC['op']=='delete'){
		$res4=pdo_delete("zhtc_user",array('id'=>$_GPC['id']));
		if($res4){
		 message('删除成功！', $this->createWebUrl('user2'), 'success');
		}else{
			  message('删除失败！','','error');
		}
	}
		if($_GPC['op']=='defriend'){
			
		$res4=pdo_update("zhtc_user",array('state'=>2),array('id'=>$_GPC['id']));
		if($res4){
		 message('拉黑成功！', $this->createWebUrl('user2',array('page'=>$_GPC['page'])), 'success');
		}else{
			  message('拉黑失败！','','error');
		}
	}
		if($_GPC['op']=='relieve'){
		$res4=pdo_update("zhtc_user",array('state'=>1),array('id'=>$_GPC['id']));
		if($res4){
		 message('取消成功！', $this->createWebUrl('user2',array('page'=>$_GPC['page'])), 'success');
		}else{
			  message('取消失败！','','error');
		}
	}
	if(checksubmit('submit2')){
      $res=pdo_update('zhtc_user',array('money +='=>$_GPC['reply']),array('id'=>$_GPC['id2']));
      if($res){
      	if($_GPC['reply']!=0){
      		if($_GPC['reply']<0){
      			$data2['type']=2;
		       $data2['note']='后台扣款';	
      		}else{
      			$data2['type']=1;
                $data2['note']='后台充值';
      		}
				$data2['money']=$_GPC['reply'];
		       $data2['user_id']=$_GPC['id2'];
		       $data2['time']=date('Y-m-d H:i:s');
		       $res2=pdo_insert('zhtc_qbmx',$data2); 
		       if($res2){
		       message('充值成功！', $this->createWebUrl('user2'), 'success');
		      }else{
		       message('充值失败！','','error');
		      }
      	}
       
    }
}
if(checksubmit('submit3')){
	$res=pdo_update('zhtc_user',array('total_score +='=>$_GPC['score']),array('id'=>$_GPC['id3']));
	if($res){
		$data2['score']=$_GPC['score'];
		$data2['user_id']=$_GPC['id3'];
		$data2['note']='后台充值';
		$data2['type']=1;
		$data2['cerated_time']=date('Y-m-d H:i:s');
		$data2['category_type']='integral';
          $data2['uniacid']=$_W['uniacid'];//小程序id
          $res2=pdo_insert('zhtc_integral',$data2);//添加红包币明细
          if($res2){
          	message('充值成功！', $this->createWebUrl('user2'), 'success');
          }else{
          	message('充值失败！','','error');
          }

      }
  }
if(checksubmit('submit5')){
	$res=pdo_update('zhtc_user',array('consume +='=>$_GPC['consume']),array('id'=>$_GPC['id5']));
	if($res){
		$data2['score']=$_GPC['consume'];
		$data2['user_id']=$_GPC['id5'];
		$data2['note']='后台充值';
		$data2['type']=1;
		$data2['cerated_time']=date('Y-m-d H:i:s');
		$data2['category_type']='consume';
          $data2['uniacid']=$_W['uniacid'];//小程序id
          $res2=pdo_insert('zhtc_integral',$data2);//添加消费劵明细
          if($res2){
          	message('充值成功！', $this->createWebUrl('user2'), 'success');
          }else{
          	message('充值失败！','','error');
          }

      }
  }
if(checksubmit('submit4')){
		if($_GPC['types']=='' || empty($_GPC['types'])){
			message('充值失败！','','error');
		}
		if ($_GPC['types']=='spike') {
			pdo_update('zhtc_user',array('spike +='=>$_GPC['cishu']),array('id'=>$_GPC['id4']));
			message('充值成功！', $this->createWebUrl('user2'), 'success');
		}
		if ($_GPC['types']=='goods_not_top') {
			pdo_update('zhtc_user',array('goods_not_top +='=>$_GPC['cishu']),array('id'=>$_GPC['id4']));
			message('充值成功！', $this->createWebUrl('user2'), 'success');
		}
		if ($_GPC['types']=='goods_top') {
			pdo_update('zhtc_user',array('goods_top +='=>$_GPC['cishu']),array('id'=>$_GPC['id4']));
			message('充值成功！', $this->createWebUrl('user2'), 'success');
		}
		if ($_GPC['types']=='fatie') {
			pdo_update('zhtc_user',array('fatie +='=>$_GPC['cishu']),array('id'=>$_GPC['id4']));
			message('充值成功！', $this->createWebUrl('user2'), 'success');
		}
}

include $this->template('web/user2');